package com.example.logistics_oa.controller;


import com.example.comment_oa.pojos.xinzi.JibenQitajine;
import com.example.comment_oa.response.AjaxResponse;
import com.example.logistics_oa.service.JibenGongzidanService;
import com.example.logistics_oa.service.JibenQitajineService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logisticsOa")
@CrossOrigin
public class JiBenQitaController {

    @Autowired
    JibenQitajineService jibenQitajineService;
    @Autowired
    JibenGongzidanService jibenGongzidanService;

    @PostMapping("/selectallQita/{jibenId}")
    public AjaxResponse selectQita(@PathVariable("jibenId")String jibenId){
        List<JibenQitajine> jibenQitajines = jibenQitajineService.selectAllQita(jibenId);
//        System.err.println(jibenQitajines);
        return AjaxResponse.success(jibenQitajines);
    }

    @PostMapping("/xiugaiQita/{zhujian}/{shijianjianshu}/{jine}/{jibenId}/{gonghao}")
    public AjaxResponse xuigaiqita(@PathVariable("zhujian") int zhujian,@PathVariable("shijianjianshu") String shijianjianshu,@PathVariable("jine")Double jine,@PathVariable("jibenId") String jibenId,@PathVariable("gonghao")String gonghao ){
        jibenQitajineService.updateJIbenQiTaShiJianAndJine(zhujian,shijianjianshu,jine);
        jibenGongzidanService.updateGongZiDanByQiTa(jine,jibenId,gonghao);
        return AjaxResponse.success();
    }

    @PostMapping("/insertOnePerson")
    public AjaxResponse insertOnePerson(@RequestBody JibenQitajine jibenQitajine){
        jibenQitajineService.insertQitaOnePerson(jibenQitajine);

        jibenGongzidanService.updateGongZiDanByQiTa(jibenQitajine.getJibenJine(),jibenQitajine.getJibenId(), jibenQitajine.getJibenGonghao());
        return AjaxResponse.success();
    }

    @PostMapping("/updateQiTaOne/{jibenzhujian}")
    public AjaxResponse updateQiTaOne(@PathVariable("jibenzhujian") int jibenzhujian){
        jibenQitajineService.updateQiTaOne(jibenzhujian);
        return AjaxResponse.success();
    }

    @PostMapping("/updateQiTaAll/{jibenId}")
    public AjaxResponse updateQiTaOne(@PathVariable("jibenId") String jibenId){
        jibenQitajineService.updateQiTaAll(jibenId);
        return AjaxResponse.success();
    }

}
